package com.situ.personal.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.situ.personal.entity.LogInfo;
import com.situ.personal.util.JDBCUtil;

public class AdmLogDao {

	public LogInfo login(String admName, String admPassword) {
		System.out.println("AdmLogDao.login()");
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		LogInfo logInfo = null;
		try {
			connection = JDBCUtil.getConnection();
			String sql = "select name,password from user where name = ? and password = ?";
			preparedStatement = connection.prepareStatement(sql);
			preparedStatement.setString(1, admName);
			preparedStatement.setString(2, admPassword);
			System.out.println(preparedStatement);
			resultSet = preparedStatement.executeQuery();
			while(resultSet.next()) {
				String name = resultSet.getString("name");
				String password = resultSet.getString("password");
				logInfo = new LogInfo(name,password);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JDBCUtil.close(connection, preparedStatement, resultSet);
		}
		
		return logInfo;
	}

}
